<?php
/**
 * Created by a front-end programmer.
 * User: Xwen
 * Date: 2018/2/9
 * Time: 17:40
 * Mail:lauwencn@gmail.com
 */
class SmartyView{
    private static $smarty = NULL;
    public function __construct(){
        if(!is_null(self::$smarty)) return;
        $smarty = new Smarty();
        //模板目录
        $smarty->template_dir = APP_TPL_PATH.'/'.CONTROLLER.'/';
        //编译
        $smarty->compile_dir = APP_COMPILE_PATH;
        //缓存
        $smarty->cache_dir = APP_CACHE_PATH;
        $smarty->left_delimiter = C('LEFT_DELIMITER');
        $smarty->right_delimiter = C('RIGHT_DELIMITER');
        $smarty->caching = C('CACHE_ON');
        $smarty->cache_lifetime = C('CACHE_TIME');
        self::$smarty = $smarty;
//        P($smarty);
    }
    protected function display($tpl){
        self::$smarty->display($tpl, $_SERVER['REQUEST_URI']);
    }
    protected function assign($var,$value){
        self::$smarty->assign($var,$value);
    }
    protected function is_cached($tpl=NULL){
        if(!C('SMARTY_ON')) half('请先开启Smarty!');
        $tpl = $this->get_tpl($tpl);
        return self::$smarty->is_cached($tpl,$_SERVER['REQUEST_URI']);
    }

}


?>